package com.github.rxyor.nio.example;

import java.nio.IntBuffer;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2020/5/31 周日 1:36 下午:00
 * @since 1.0.0
 */
public class NioIntBuffer {

    public static void main(String[] args) {
        NioIntBuffer example = new NioIntBuffer();
        example.testIntBuffer();
    }

    public void testIntBuffer(){
        IntBuffer intBuffer = IntBuffer.allocate(10);
        System.out.println("capacity:" + intBuffer.capacity());
        System.out.println("limit:" + intBuffer.limit());

        for (int i = 0; i < 5; i++) {
            intBuffer.put(i);
        }

        System.out.println("before flip, limit:" + intBuffer.limit());
        intBuffer.flip();
        System.out.println("after flip, limit:" + intBuffer.limit());
        System.out.println("begin read...");
        while (intBuffer.hasRemaining()){
            System.out.println("-------------------------");
            System.out.println("position:" + intBuffer.position());
            System.out.println("limit:" + intBuffer.limit());
            System.out.println("capacity:" + intBuffer.limit());
            System.out.println("element:" + intBuffer.get());
            System.out.println("-------------------------");
        }

    }

}
